# -*- coding: UTF-8 -*-
import json

from pymongo import MongoClient
from datetime import datetime, timezone
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import time


class TimeUtils:
    def __init__(self):
        pass

    @staticmethod
    def timestamp2utc_str(timestamp_sec_value):
        return str(datetime.utcfromtimestamp(timestamp_sec_value))

    @staticmethod
    def timestamp2local_str(timestamp_sec_value):
        return str(datetime.fromtimestamp(timestamp_sec_value))

    @staticmethod
    def local2utc_str(local_time_str):
        pass

    @staticmethod
    def utc2timestamp(s):
        begin_timestamp = int(
            datetime.strptime(s, '%Y-%m-%d %H:%M:%S').replace(tzinfo=timezone.utc).timestamp())
        return begin_timestamp

    @staticmethod
    def local2timestamp(s):
        return int(datetime.strptime(s, '%Y-%m-%d %H:%M:%S').timestamp())


if __name__ == '__main__':
    print(TimeUtils.utc2timestamp('2019-03-12 07:00:00'))
    print(TimeUtils.timestamp2utc_str(1543622400))
    exit()
    # time_stamp_value = 1527811200
    time_stamp_value = 1527811200
    time_utils = TimeUtils()
    utc = time_utils.timestamp2utc_str(time_stamp_value)
    print('utc: ', utc)
    local = time_utils.timestamp2local_str(time_stamp_value)
    print('local: ', local)

    # 1551409200
    # t = time_utils.local2timestamp('2018-06-01 08:00:00')
    t = time_utils.local2timestamp('2018-12-07 7:59:00')
    print(t)
    pass

# desired_width = 320
# pd.set_option('display.width', desired_width)
# pd.set_option('display.max_columns', 20)
#
# features_db = MongoClient('mongodb://39.104.227.148:27019/')['predict_signal']
# cursor = features_db['return_15_72'].find({})
# df = pd.DataFrame(list(cursor))
#
# df.plot()
# plt.show()
# df = df[::200]
# # df = df[400:420]
#
# fig = plt.figure(facecolor='white', figsize=(40, 30))
# # ax = fig.add_subplot(111)
#
# x = df['predict_time'].tolist()
# tick = np.arange(len(df))
# print(tick)
#
# plt.plot(df['predict_return'].tolist(), label='Prediction')
# plt.xticks(tick, x)
# plt.gcf().autofmt_xdate()
# plt.legend()
# plt.show()

# 1527811200
